$(document).ready(function(){
	initData(1); //实例化
	//jquery 限制只能输入数字
	$("#goPage").keyup(function(){
		 $(this).val($(this).val().replace(/\D|^0/g,''));
	 }).bind("paste",function(){  //CTR+V事件处理     
		 $(this).val($(this).val().replace(/\D|^0/g,''));     
	 }).css("ime-mode", "disabled"); //CSS设置输入法不可用  
	//反选            
	$("#checkOpp,#checkAll").click(function() {
		$("[name='items']:checkbox").each(function() {                       
			$(this).attr("checked", !$(this).attr("checked"));  
		});
	});
	/**获得选中多个items的值*/
	$("#oneKey").click(function() {      
		//var Str = "你选中的是：\n\r";    
		var Str = "";
		$("[name='items']:checkbox:checked").each(function() {            
			Str += $(this).val()+",";     
		});
		if(Str==""){
			$.dialog.alert('请勾选后再确认！');
			$("#checkItem").val("");
		}else{
			$("#checkItem").val(Str);
		}
	});
	
});//ready end


//到数据库提取数据进行一个分页显示，需要传递过去的数据有年级的id 层次的id,校区id，班级id，教师id
/**当前使用**/
function initData(currentPage){
	/**参数Start*/
	var USERID = $("#USERID").val();
	var code = $("#code").val();
	/**参数End*/
	var pageSize = 10;
	var path = $("#path").val()+"/MonthUser.action";
	var pageCount = "";
   	$.ajax({
	      type: "post",
	      url: path,                  
	      dataType: "json",
	      cache: false, //默认为true,设为false将不缓存页面，开发时使用。正式使用时可注释掉。
	      data: "currentPage="+currentPage+"&pageSize="+pageSize+"&USERID="+USERID+"&code="+code,
	      
	      beforeSend: function(){$("#divload").show();$("#divshow").hide();},//发送数据之前
	      complete: function(){$("#divshow").show();$("#divload").hide();},
	      success: function(json){
	    	  $("#showtable tr:gt(0)").remove();//移除Id为result的表格里的行，从第二行开始
	    	  if(json[0].code == 1){$("#month").html("本月");}
	    	  if(json[0].code == 2){$("#month").html("上月");}
	    	  if(json[0].code == 3){$("#month").html("近三个月");}
//	    	  onclick="confim(0,0,);";
	    	  $("#oneKey").attr("onclick","confim(0,0,"+currentPage+");");
	    	  $("#late").html(json[0].lateSum);
	    	  $("#early").html(json[0].earlySum);
	    	  //总记录数
	    	  pageCount = json[0].pageCount;
		    	  if(pageCount != 0){
			          //遍历取数据
			    	  for(var i = 0; i < json.length; i++){
			    		  $("#dataShow").append("<tr>"+
			    		  "<td height='20'>"+json[i].check+"</td>"+
				          "<td>"+json[i].userName+"</td>"+
				          "<td title='指纹所在校区' class='skyblue'>"+json[i].schName+"</td>"+
				          "<td>"+json[i].attWeek+"</td>"+
				          "<td><a href='javascript:void(0);' onclick='opdg("+json[i].attId+");'>"+json[i].attDate+"</a></td>"+
//				          "<td>"+json[i].attDate+"</td>"+
				          "<td>"+json[i].worktime+"</td>"+
				          "<td>"+json[i].closingtime+"</td>"+
				          "<td>"+json[i].state+"</td>"+
				          "<td>"+json[i].latetime+"</td>"+
				          "<td>"+json[i].earlytime+"</td>"+
				          "<td title='"+json[i].desc+"' class='skyblue'>"+json[i].subDesc+"</td>"+
				          "<td>"+json[i].confirm+"</td>"+
				        "</tr>");
			    	  }
			    	  	//行交替颜色
                      $("#showtable tr:even").css("background-color","#f5f5f5");
	                   	$("#showtable tr").live("mouseenter",function(){
	                   		$(this).addClass("lightbluebg");
	                   	}).live("mouseleave",function(){
	                   	    $(this).removeClass("lightbluebg");
	                   	});
		    	  }else{
		    		  $.dialog.tips('没有匹配的数据！',1,'alert.gif');
		    		  $("#dataShow").append("<tr><td colspan='12'>没有匹配的数据！</td></tr>");
		    	  }
	    	  
		    	  //漂亮的蓝色提示哈
		    	  $('.skyblue').poshytip({
		    			className: 'tip-skyblue',
		    			bgImageFrameSize: 9,
		    			offsetX: 0,
		    			offsetY: 20
		    	  });
	    	  
	    	  	//设定分页
	    	    $("#totalRows").html(pageCount);//总记录数
	    	    $("#currentPage").html(currentPage);//当前页数
	    	    $("#pageSize").html(pageSize); //每页显示记录数
	    	    
	    	    var totalPageNum = 0;
	    	    if((pageCount % pageSize) == 0){
		    	     $("#totalPages").html(pageCount / pageSize);
		    	     totalPageNum = pageCount / pageSize;
		    	     
	    	    }else{
		    	     $("#totalPages").html(parseInt(pageCount / pageSize) + 1);
		    	     totalPageNum = parseInt(pageCount / pageSize) + 1;
	    	    }
	    	    $("#totalPge").val(totalPageNum); //将总页数赋值给totalPge隐藏域
	    	    //设定上一页，下一页  首页、尾页的链接
	    	    if(pageCount <= pageSize){
	    	    	 $("#first").attr("href","javascript:void(0);");
	    	    	 $("#previous").attr("href","javascript:void(0);");
	    	    	 $("#next").attr("href","javascript:void(0);");
	    	    	 $("#last").attr("href","javascript:void(0);");
	    	    	 $("#go").removeAttr("onclick");
	    	    }else if(currentPage == 1){
	    	    	 $("#first").attr("href","javascript:void(0);");
	    	    	 $("#previous").attr("href","javascript:void(0);");
	    	    	 $("#next").attr("href","javascript:initData("+(currentPage+1)+");");
	    	    	 $("#last").attr("href","javascript:initData("+totalPageNum+");");
	    	    }else if(currentPage == totalPageNum){
	    	    	 $("#first").attr("href","javascript:initData(1);");
	    	    	 $("#previous").attr("href","javascript:initData("+(currentPage-1)+");");
	    	    	 $("#next").attr("href","javascript:void(0);");
	    	    	 $("#last").attr("href","javascript:void(0);");
	    	    }else{
	    	    	 $("#first").attr("href","javascript:initData(1);");
	    	    	 $("#previous").attr("href","javascript:initData("+(currentPage-1)+");");
	    	    	 $("#next").attr("href","javascript:initData("+(currentPage+1)+");");
	    	    	 $("#last").attr("href","javascript:initData("+totalPageNum+");");
	    	    }
	    	    
	      }//success END
	}); //ajax  END
}//分页结束

//输入页数跳转页面
function goOnclick(){
	var pageNum = $("#goPage").val();
	var totalPge = $("#totalPge").val();
	if(pageNum != "" && parseInt(pageNum) <= parseInt(totalPge)){
		initData(pageNum);
	}else{
		$.dialog.tips('请输入总页数以内的整数！',3,'alert.gif');
	}
}

//确认考勤
function confim(arg,arg1,currentPage){
//	var qstr = getCheckboxItem();
	var qstr = $("#checkItem").val();
//	alert(qstr+"---"+arg);
	if(qstr=="" && arg==0){
		$.dialog.alert('请勾选后再确认！');
	}else{
		$.dialog.confirm('你确定考勤没问题吗？', function(){
			var path = $("#path").val()+"/Choose";
			var dat;
			if(arg1==0){
				dat="qstr="+qstr+"&currentPage="+currentPage;
			}else{
				dat="qstr="+arg1+"&currentPage="+currentPage;
			}
			$.ajax({
			      type: "post",
			      url: path,
			      dataType: "json",
			      data: dat,
			      beforeSend: function(){ $.dialog.tips('正在确认中...',3,'loading.gif');},//发送数据之前
//			      complete: function(){},
			      success: function(json){
			    	  var curPage = json[0].curPage;
			    	  if(json[0].jason == 1){
			    		  initData(curPage);
			    		  $.dialog.tips('已确认！',3,'success.gif');
			    	  }else{
			    		  $.dialog.tips('您好，确认失败，请联系管理员处理！',3,'error.gif'); 
			    	  }
			      }
			});
			
		}, function(){
		    $.dialog.tips('已取消！',1,'alert.gif');
		});
	}
}
//打卡详细记录
function opdg(attId){
	var path = $("#path").val()+'/attend/myattend/winp.jsp?attId='+attId;
    $.dialog({
    	lock: true,
    	fixed:true,
    	title: '打卡详细记录',
    	content:'url:'+path,
    	width: '450px',
		height: 330,
		max: false,
		min: false
    });
}
//申诉单
function opens(userId,attId,currentpage){
	var path = $("#path").val()+'/attend/myattend/winS.jsp?userId='+userId+'&attId='+attId;
    $.dialog({ 
    	lock: true,
    	fixed:true,
    	title:'考勤申诉', 
    	content:'url:'+path,
    	width: '600px',
		height: 350,
		max: false,
		min: false,
		close: function(){
	       //this.reload();
	       initData(currentpage);
	    },
	    /*okVal: '提交',
	    ok: function(){
	        //this.reload();
	        return false;
	    },*/
    	cancelVal: '关闭',
		cancel: function(){
	        //this.reload();
			initData(currentpage);
	    }
    });
}
